package com.td.core.communication.obj;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.td.core.communication.Sendable;

public class PreGameInfo implements Sendable<PreGameInfo> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private PlayerInfo myPlayer;
	private int timeToGame;
	private List<PlayerInfo> playersConnected;
	
	public PreGameInfo() {
		myPlayer = new PlayerInfo();
		timeToGame = 0;
		playersConnected = new ArrayList<PlayerInfo>();
	}
	
	public PreGameInfo(PreGameInfo pgi) {
		myPlayer = pgi.myPlayer.getCopy();
		timeToGame = pgi.timeToGame;
		playersConnected = new ArrayList<PlayerInfo>(pgi.playersConnected);
	}

	public synchronized PlayerInfo getMyPlayer() {
		return myPlayer;
	}

	public synchronized void setMyPlayer(PlayerInfo myPlayer) {
		this.myPlayer = myPlayer;
	}

	public synchronized int getTimeToGame() {
		return timeToGame;
	}

	public synchronized void setTimeToGame(int timeToGame) {
		this.timeToGame = timeToGame;
	}

	public synchronized List<PlayerInfo> getPlayersConnected() {
		return playersConnected;
	}

	public synchronized void setPlayersConnected(List<PlayerInfo> playersConnected) {
		this.playersConnected = playersConnected;
	}

	@Override
	public synchronized void copyTo(PreGameInfo obj) {
		synchronized (obj) {
			this.myPlayer.copyTo(obj.myPlayer);
			obj.timeToGame = this.timeToGame;
			obj.playersConnected.clear();
			Iterator<PlayerInfo> it = this.playersConnected.iterator();
			while(it.hasNext()) {
				obj.playersConnected.add(new PlayerInfo(it.next()));
			}		
		}
	}

	@Override
	public PreGameInfo getCopy() {
		return new PreGameInfo(this);
	}
}
